const express = require('express');
const router = express.Router();
const teamController = require('../controllers/teamController');
const { auth, manager } = require('../middlewares/auth');
const { validate, teamValidation } = require('../utils/validator');

// 所有路由都需要认证
router.use(auth);

// GET /api/teams - 获取团队列表
router.get('/', teamController.getTeams);

// GET /api/teams/:id - 获取单个团队
router.get('/:id', teamController.getTeam);

// POST /api/teams - 创建团队 (需要管理员或经理权限)
router.post('/', [manager, validate(teamValidation.create)], teamController.createTeam);

// PUT /api/teams/:id - 更新团队 (需要管理员或经理权限)
router.put('/:id', [manager, validate(teamValidation.update)], teamController.updateTeam);

// DELETE /api/teams/:id - 删除团队 (需要管理员或经理权限)
router.delete('/:id', manager, teamController.deleteTeam);

// POST /api/teams/:id/members - 添加团队成员 (需要管理员或经理权限)
router.post('/:id/members', [manager, validate(teamValidation.addMember)], teamController.addMember);

// DELETE /api/teams/:id/members/:userId - 移除团队成员 (需要管理员或经理权限)
router.delete('/:id/members/:userId', manager, teamController.removeMember);

module.exports = router; 